package cn.itcast.user.web;

import cn.itcast.user.pojo.User;
import cn.itcast.user.properties.PatternProperties;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope // 支持Nacos的动态刷新功能
public class UserController {

    @Autowired
    private UserService userService;

    //@Value("${pattern.datefromat}")
    private String dateformat;

    @Autowired
    private PatternProperties patternProperties;

    @Value("${name}")
    private String name;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }

    @GetMapping("/lunger")
    private String lun(@RequestHeader String lun) {
        return "lunger:" + lun;
    }

    @GetMapping("/now")
    public String now() {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(name);
        return now.format(DateTimeFormatter.ofPattern(patternProperties.getDatefromat(), Locale.CHINA));
    }
}
